﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 图解算法数据结构._58_MaxSlidingWindow
{
    class MainProject
    {
        static void Main(string[] args)
        {
            Console.WriteLine(MaxSlidingWindow(new int[] { 1, 3, -1, -3, 5, 3, 6, 7 },3));
            Console.ReadKey();
        }
        public static int[] MaxSlidingWindow(int[] nums, int k)
        {
            if (nums.Length==0) return nums;
            //队列or双指针
            int[] array = new int[nums.Length - (k - 1)];
            Queue<int> que = new Queue<int>();
            int index = 0;
            for (int i = 0; i < nums.Length; i++)
            {
                que.Enqueue(nums[i]);
                if (que.Count == k)
                {
                    array[index] = que.Max();
                    que.Dequeue();
                    index++;
                }
            }
            return array;
        }
    }
}
